package com.wsd.common;

import com.wsd.constant.ResultCode;

import java.io.Serializable;

/**
 * @author  zhangqizeng
 * 通用 结果返回类
 */
public class Result<T> implements Serializable {

    // 结果状态码
    private Integer resultCode;
    // 结果消息
    private String resultMsg;
    // 结果数据
    private T data;

    public Result() {
        super();
    }

    public Result(Integer code, String msg, T data) {
        this.resultCode = code;
        this.resultMsg = msg;
        this.data = data;
    }

    /**
     * 根据状态码枚举设置状态码和状态信息的值
     * @param code 状态码枚举
     */
    public void setResultCode(ResultCode code) {
        this.resultCode = code.getCode();
        this.resultMsg = code.getMessage();
    }

    public Integer getResultCode() {
        return resultCode;
    }

    public void setResultCode(Integer code) {
        this.resultCode = code;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public void setResultMsg(String msg) {
        this.resultMsg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    @Override
    public String toString() {
        return "Result{" +
                "resultCode=" + this.resultCode +
                ", resultMsg='" + this.resultMsg + '\'' +
                ", data=" + this.data +
                '}';
    }

}
